package com.ocom.human.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ocom.common.entity.human.EntityPersonTagRelation;
import com.ocom.common.request.human.GetByPersonTagVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface IDaoPersonTagRelation extends BaseMapper<EntityPersonTagRelation> {

    @Select({"<script>",
            "SELECT " +
                    " tr.p_id, " +
                    " t.tag_id, " +
                    " t.tag_name, " +
                    " t.group_no, " +
                    " tt.group_name, " +
                    " tt.color " +
                    " FROM " +
                    " person_tag_relation tr " +
                    " LEFT JOIN person_tag t ON tr.com_id = t.com_id " +
                    " AND tr.tag_id = t.tag_id " +
                    " LEFT JOIN person_tag_type tt ON t.com_id = tt.com_id " +
                    " AND t.group_no = tt.group_no " +
                    " WHERE " +
                    " tr.com_id = #{comId} " +
                    " AND t.state = 1 " +
                    " <when test=\"pIds != null and pIds.size() > 0\" > " +
                    " AND tr.p_id in " +
                    " <foreach collection='pIds' item='item' open='(' separator=',' close=')'> " +
                    " #{item}  " +
                    " </foreach> " +
                    " </when>" +
                    " ORDER BY " +
                    " tr.p_id" +
                    "</script>"})
    List<GetByPersonTagVo> getByPersonTag(@Param("comId") Long comId, @Param("pIds") List<Long> pIds);
}
